package com.zhuss.core.processor;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.diss.UpdateDissBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.core.db.dao.ext.DissDao;
import com.zhuss.core.db.entity.Diss;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.DzcxException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.util.JsonUtil;

/**
 * @description: 吐槽修改
 * @author: zhushanshuo
 * @create: Tue Feb 02 15:22:08 CST 2021
 **/
@Component("dissUpdate")
public class DissUpdate extends AbstractProcessor<Object, UpdateDissBo> implements Processor<Object, UpdateDissBo> {

    @Autowired
    private DissDao dissDao;

    @Autowired
	@Qualifier("dissRead")
	private DissRead dissRead;

    /**
     * 校验
     */
    @Override
    public void check(UpdateDissBo bo) throws DzcxException {
    	Long dissId = bo.getDissId();
    	String name = bo.getTitle();
    	if (dissId == null || dissId <= 0l) {
    		throw new DzcxException(ExceptionCode.意见反馈ID为空);
    	}
		if (name == null || "".equals(name.trim())) {
			throw new DzcxException(ExceptionCode.意见反馈标题为空);
		}

		if (bo.getContent() == null || "".equals(bo.getContent().trim())) {
			throw new DzcxException(ExceptionCode.意见反馈内容为空);
		}

//    	List<Diss> list = dissRead.listNotId(name, dissId);
//    	if (!list.isEmpty()) {
//    		 throw new DzcxException(ExceptionCode.建议意见标题已存在);
//    	}
    }


    /**
     * 操作方法
     */
    @Override
    public Object process(UpdateDissBo param) {
    	Diss record = new Diss();
    	record.setDissId(param.getDissId());
    	record.setTitle(param.getTitle());
    	record.setContent(param.getContent());
    	record.setStatus(param.getStatus());


    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	dissDao.updateByPrimaryKeySelective(record);
        return null;
    }

    /**
     * 操作日志
     */
	@Override
	public Object log(UpdateDissBo param) throws DzcxException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.基础模块.key());
    	record.setAction(LogActionEnum.意见反馈修改.key());
    	record.setTargetId(param.getDissId());
    	record.setTargetName(param.getTitle());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());

    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
